package com.coderush.admin.core.common;

import java.io.Serializable;
import java.util.List;

public class PageResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /** 一共有多个条记录 */
    private long total;
    /** 当前是第几页 */
    private int pageNum;
    /** 每页显示多少条记录 */
    private int pageSize;
    /** 一共有多少页 */
    private int pages;
    /** 当前页的数据 */
    private List<T> list;

    public PageResult() {}

    public PageResult(long total, int pageNum, int pageSize, List<T> list) {
        this.total = total;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.pages = (int) Math.ceil((double) total / pageSize);
        this.list = list;
    }

    // Getters and Setters
    public long getTotal() { return total; }
    public void setTotal(long total) { this.total = total; }

    public int getPageNum() { return pageNum; }
    public void setPageNum(int pageNum) { this.pageNum = pageNum; }

    public int getPageSize() { return pageSize; }
    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    public int getPages() { return pages; }
    public void setPages(int pages) { this.pages = pages; }

    public List<T> getList() { return list; }
    public void setList(List<T> list) { this.list = list; }

    @Override
    public String toString() {
        return "PageResult{" +
                "total=" + total +
                ", pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", pages=" + pages +
                ", listSize=" + (list != null ? list.size() : 0) +
                '}';
    }
}